package mortal.game.view.msgbroad
{
	import com.gengine.utils.*;
	import com.greensock.*;
	import flash.display.*;
	import flash.text.*;
	import flash.utils.*;
	import mortal.component.gconst.*;
	
	public class IssmNoticItem extends Sprite
	{
		private var _textField:TextField;
		private var _timerKey:int;
		private var _inTween:TweenMax;
		private var _outTween:TweenMax;
		private var _endFun:Function;
		
		public function IssmNoticItem()
		{
			mouseEnabled = false;
			mouseChildren = false;
			this._textField = new TextField();
			this._textField.selectable = false;
			this._textField.multiline = true;
			this._textField.wordWrap = true;
			this._textField.width = 500;
			this._textField.filters = [FilterConst.nameGlowFilter];
			var textFormat:* = new TextFormat("", 14, 16776960, true, null, null, null, null, TextFormatAlign.CENTER);
			this._textField.defaultTextFormat = textFormat;
			this._textField.autoSize = TextFieldAutoSize.CENTER;
			addChild(this._textField);
		}
		
		private function onInEnd() : void
		{
			this._timerKey = setTimeout(this.timerOutHandler, 60000);
		}
		
		private function onOutEnd() : void
		{
			if (this._endFun != null)
			{
				this._endFun.call(this, this);
			}
		}
		
		private function timerOutHandler() : void
		{
			this._outTween = TweenMax.to(this._textField, 0.3, {alpha:0, onComplete:this.onOutEnd});
		}
		
		public function updateData(info:String, fun:Function = null, bol:Boolean = true) : void
		{
			this._textField.htmlText = HTMLUtil.addColor(info, "#ffff00");
			this._textField.height = this._textField.textHeight;
			if (bol)
			{
				this._textField.alpha = 0;
				this._textField.y = 20;
				this._inTween = TweenMax.to(this._textField, 0.3, {alpha:1, y:0, onComplete:this.onInEnd});
			}
			else
			{
				this._textField.alpha = 1;
				this._textField.y = 0;
				this.onInEnd();
			}
		}
		
		public function killInEase() : void
		{
			if (this._inTween && this._inTween.active)
			{
				this._textField.y = 0;
				this._textField.alpha = 1;
				this._inTween.kill();
				this.onInEnd();
			}
		}
		
		public function dispose() : void
		{
			this._endFun = null;
			clearTimeout(this._timerKey);
			if (this._inTween && this._inTween.active)
			{
				this._inTween.kill();
			}
			else if (this._outTween && this._outTween.active)
			{
				this._outTween.kill();
			}
			this._textField.alpha = 1;
			this._textField.y = 0;
		}
		
		override public function get height() : Number
		{
			return this._textField.textHeight;
		}
		
		override public function get width() : Number
		{
			return this._textField.width;
		}
	}
}
